import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
const path = require('path')

export default defineConfig((prop) => {
  return {
    plugins: [vue()],
    base: prop.mode === 'prod' || prop.mode === 'test' ? '/xqc_h5/' : './',
    build: {
      assetsDir: 'static',
      outDir: prop.mode === 'prod' ? 'dist_prd' : 'dist_test'
    },
    resolve: {
      alias: {
        '@': path.join(__dirname, './src'),
        '~': path.join(__dirname, './src/components'),
        '^': path.join(__dirname, './src/utils')
      }
    },
    css: {
      preprocessorOptions: {
        less: {
          additionalData: `@import "${path.resolve(__dirname, 'src/assets/css/index.less')}";`
        }
      }
    },
    server: {
      host: 'localhost',
      port: 8081,
      https: false,
      open: false, //启动时是否自动在浏览器打开，值为字符串时，会被用作 URL 的路径名。
      hmr: true,
      proxy: {
        '/webApi': {
          //target: 'http://localhost:9508/xqc_api/v1.0/',
           target: 'http://8.142.18.200/xqc_api/v1.0/',
          // target: 'http://zs.xiaoqin.com.cn/xqc_api/v1.0/',
          ws: false,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/webApi/, '')
        }
      }
    }
  }
})
